<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登陆-仓储管理系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/lib/layui/css/layui.css" media="all">
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        body {background-image:url("resources/images/bg.jpg");height:100%;width:100%;}
        #container{height:100%;width:100%;}
        input:-webkit-autofill {-webkit-box-shadow:inset 0 0 0 1000px #fff;background-color:transparent;}
        .admin-login-background {width:300px;height:300px;position:absolute;left:50%;top:40%;margin-left:-150px;margin-top:-100px;}
        .admin-header {text-align:center;margin-bottom:20px;color:#ffffff;font-weight:bold;font-size:40px}
        .admin-input {border-top-style:none;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;height:50px;width:300px;padding-bottom:0px;}
        .admin-input::-webkit-input-placeholder {color:#a78369}
        .layui-icon-username {color:#a78369 !important;}
        .layui-icon-username:hover {color:#9dadce !important;}
        .layui-icon-password {color:#a78369 !important;}
        .layui-icon-password:hover {color:#9dadce !important;}
        .admin-input-username {border-top-style:solid;border-radius:10px 10px 0 0;}
        .admin-input-verify {border-radius:0 0 10px 10px;}
        .admin-button {margin-top:20px;font-weight:bold;font-size:18px;width:300px;height:50px;border-radius:5px;background-color:#a78369;border:1px solid #d8b29f}
        .admin-icon {margin-left:260px;margin-top:10px;font-size:30px;}
        i {position:absolute;}
        .admin-captcha {position:absolute;margin-left:205px;margin-top:-40px;}
    </style>
</head>
<body>
<div id="container">
    <div></div>
    <div class="admin-login-background">
        <div class="admin-header">
            <span>仓储管理系统</span>
        </div>
        <form class="layui-form" action="" method="post">
            <div>
                <i class="layui-icon layui-icon-username admin-icon"></i>
                <input type="text" name="username" value="system" placeholder="请输入用户名" autocomplete="off" class="layui-input admin-input admin-input-username" value="admin">
            </div>
            <div>
                <i class="layui-icon layui-icon-password admin-icon"></i>
                <input type="password" name="password" value="123456" placeholder="请输入密码" autocomplete="off" class="layui-input admin-input" value="123456">
            </div>
            <div>
                <input type="text" name="captcha" placeholder="请输入验证码" autocomplete="off" class="layui-input admin-input admin-input-verify" value="xszg">
                <img class="admin-captcha" id="captcha" onclick="getCaptcha()" width="90" height="30" src="resources/images/captcha.jpg" >
            </div>
            <button type="button" class="layui-btn admin-button" lay-submit="" lay-filter="login">登 陆</button>
        </form>
    </div>
</div>

<script src="resources/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="resources/lib/layui/layui.js" charset="utf-8"></script>
<script src="resources/lib/jquery-3.4.1/jquery.cookie.min.js" charset="utf-8"></script>
<script src="resources/lib/common/common.js" charset="utf-8"></script>
<script>
	
	//前端生成一个5位数
	var key=Math.floor(Math.random()*10000+10000);  
	//alert(key);
	//给图片设置新的src
	$("#captcha").attr("src",api+"login/captcha?key="+key);
	
	function getCaptcha(){
		key=Math.floor(Math.random()*10000+10000);  
		$("#captcha").attr("src",api+"login/captcha?key="+key);
	}
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;
        // 登录过期的时候，跳出ifram框架
        if (top.location != self.location) top.location = self.location;

        // 进行登录操作
        form.on('submit(login)', function (data) {
            var btn=$(this);
			btn.text("登 入 中...").attr("disabled","disabled").addClass("layui-disabled");
			$.ajax({
				url:api+"login/doLogin",
				method:"post",
				data:{username:data.field.username,password:data.field.password,
				key:key,captcha:data.field.captcha},
				success:function(res){
					layer.msg(res.msg);
					if(res.code!=0){//登陆失败
						btn.text("登 入").attr("disabled",false).removeClass("layui-disabled");
					}else{//登陆成功
						//把token写到cookie
						//alert(res.token);
						$.cookie('TOKEN', res.token, { expires: 7 });  //登陆成功这后把token放到cookie里面
						window.location.href = "/WEB-ERP/index.html";
					}
				},
				error:function(){
					layer.msg("登陆失败");
					btn.text("登 入").attr("disabled","").removeClass("layui-disabled");
				}
			})
            return false;
        });
    });
</script>
</body>
</html>